package ldh.im.base.service;

import ldh.im.dto.codec.CodecFactory;

import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;

public class AuthAbleService {

    private static AuthAbleService instance;
    private Set<Integer> noAuthCodeSet;

    private AuthAbleService() {
        noAuthCodeSet = new ConcurrentSkipListSet<>();
        initRegister();
    }

    public static AuthAbleService getInstance() {
        if (instance == null) {
            synchronized (CodecFactory.class) {
                if (instance == null) {
                    instance = new AuthAbleService();
                }
            }
        }
        return instance;
    }

    public boolean isNoAuth(int authCode) {
        return noAuthCodeSet.contains(authCode);
    }

    private void initRegister() {
        noAuthCodeSet.add("login".hashCode());
        noAuthCodeSet.add("reconnection".hashCode());
    }
}
